package com.luqm.mall.mallsearch.controller;

import com.luqm.mall.mallsearch.service.MallSearchService;
import com.luqm.mall.mallsearch.vo.EsSearchResult;
import com.luqm.mall.mallsearch.vo.SearchParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping({"/","/list.html"})
    public String listPage(SearchParam param, Model model, HttpServletRequest servletRequest){
        String queryString = servletRequest.getQueryString();
        param.set_queryString(queryString);
        EsSearchResult result=mallSearchService.search(param);
        model.addAttribute("result",result);
        return "list";
    }
}
